<script>
	import config from '@/utils/config.js';
	export default {
		data(){
			return {
				route:"",
			}
		},
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			this.getPage();
			// this.getToken();
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			getToken(){
				uni.request({
					url: config.host + '/huishou/pcLogin/getAppLoginInfo', //接口地址。
					data: {
						token: uni.getStorageSync('token'),
					},
					method: 'POST',
					header: {
						'content-type': 'application/json;charset=UTF-8'
					},
					success: (res) => {
						if (Object.keys(res.data.item).length == 0) {
							uni.showToast({
								icon: 'none',
								title: '身份已过期，请重新登录！'
							});
							if(this.route != [] && this.route.length != 0){
								setTimeout(() => {
									uni.navigateTo({
										url: '../login/index'
									})
								}, 800);
							}
							
						} else {
							setTimeout(() => {
								uni.navigateTo({
									url: '../index/index'
								})
							}, 300);
						}
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				});
			},
			getPage(){
				this.route = getCurrentPages(); // 获取当前打开过的页面路由数组
			}
			
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	    @import "uview-ui/index.scss";
</style>
